package org.teamh.gui.lobby;

import de.lessvoid.nifty.controls.ListBox.ListBoxViewConverter;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.elements.render.TextRenderer;

public class ChatListBoxViewConverter implements
		ListBoxViewConverter<TextRenderer> {

	private Object obj;

	@Override
	public void display(Element element, TextRenderer item) {
		TextRenderer renderer = element.getRenderer(TextRenderer.class);

		if (renderer == null) {
			return;
		}
		if (item != null) {
			renderer.setText(item.getOriginalText());
			renderer.setColor(item.getColor());
			this.obj = item;
		} else {
			renderer.setText("item is null");
		}
	}

	@Override
	public int getWidth(Element element, TextRenderer item) {
		TextRenderer renderer = element.getRenderer(TextRenderer.class);
		if (renderer == null) {
			return 0;
		}
		return element.getRenderer(TextRenderer.class).getFont()
				.getWidth(item.toString());
	}

	public Object getStoredObject() {
		return obj;
	}

}
